Dancing links

نویسنده

  • Donald E. Knuth
چکیده

My purpose is to discuss an extremely simple technique that deserves to be better known. Suppose x points to an element of a doubly linked list; let L[x] and R[x] point to the predecessor and successor of that element. Then the operations L R[x] ← L[x], R L[x] ← R[x] (1) remove x from the list; every programmer knows this. But comparatively few programmers have realized that the subsequent operations L R[x] ← x, R L[x] ← x (2) will put x back into the list again. This fact is, of course, obvious, once it has been pointed out. Yet I remember feeling a definite sense of " Aha! " when I first realized that (2) would work, because the values of L[x] and R[x] no longer have their former semantic significance after x has been removed from its list. Indeed, a tidy programmer might want to clean up the data structure by setting L[x] and R[x] both equal to x, or to some null value, after x has been deleted. Danger sometimes lurks when objects are allowed to point into a list from the outside; such pointers can, for example, interfere with garbage collection. Why, therefore, am I sufficiently fond of operation (2) that I am motivated to write an entire paper about it? The element denoted by x has been deleted from its list; why would anybody want to put it back again? Well, I admit that updates to a data structure are usually intended to be permanent. But there are also many occasions when they are not. For example, an interactive program may need to revert to a former state when the user wants to undo an operation or a sequence of operations. Another typical application arises in backtrack programs [16], which enumerate all solutions to a given set of constraints. Backtracking, also called depth-first search, will be the focus of the present paper. The idea of (2) was introduced in 1979 by Hitotumatu and Noshita [22], who showed that it makes Dijkstra's well-known program for the N queens problem [6, pages 72–82] run nearly twice as fast without making the program significantly more complicated. Floyd's elegant discussion of the connection between backtracking and nondeterminis-tic algorithms [11] includes a precise method for updating data structures before choosing between alternative lines of computation, and for downdating the data when it is time to explore another line. In general, …

برای دانلود رایگان متن کامل این مقاله و بیش از 32 میلیون مقاله دیگر ابتدا ثبت نام کنید

ثبت نام

اگر عضو سایت هستید لطفا وارد حساب کاربری خود شوید

منابع مشابه

Changes to Saccade Behaviors in Parkinson’s Disease Following Dancing and Observation of Dancing

BACKGROUND The traditional view of Parkinson's disease (PD) as a motor disorder only treated by dopaminergic medications is now shifting to include non-pharmacologic interventions. We have noticed that patients with PD obtain an immediate, short-lasting benefit to mobility by the end of a dance class, suggesting some mechanism by which dancing reduces bradykinetic symptoms. We have also found t...

متن کامل

A Parallel Programming Approach to Solve the Exact Cover Problem

In this paper we present the solution of large exact cover problem using Message Passing Interface. The exact cover problem is a kind of constraint satisfaction problem. The exact cover problem is mathematically interesting to solve different mathematical puzzles and may arise practical interests in different fields. The exact cover problem is NPcomplete and the computational complexity to solv...

متن کامل

On Jigsaw Sudoku Puzzles and Related Topics Bachelor Thesis

Using memoization and various other optimization techniques, the number of dissections of the n × n square into n polyominoes of size n is computed for n ≤ 8. On this task our method outperforms Donald Knuth’s Algorithm X with Dancing Links. The number of jigsaw sudoku puzzle solutions is computed for n ≤ 7. For every jigsaw sudoku puzzle polyomino cover with n ≤ 6 the size of its smallest crit...

متن کامل

Using general semantic information to help the terminology structuration

We report in this paper the results of a preliminairy experience on the relevance of general semantic information in the context of a terminology structuration. As resources supplying specialised semantic information in the domain of the studied documents are missing, we use general semantic information to structure a terminology. By exploiting a general synonymy dictionary, we attempt to infer...

متن کامل

Multi-Agent Plan Recognition: Formalization and Algorithms

Multi-Agent Plan Recognition (MAPR) seeks to identify the dynamic team structures and team behaviors from the observations of the activity-sequences of a set of intelligent agents, based on a library of known team-activities (plan library). It has important applications in analyzing data from automated monitoring, surveillance, and intelligence analysis in general. In this paper, we formalize M...

متن کامل

Median Filtering is Equivalent to Sorting

This work shows that the following problems are equivalent, both in theory and in practice: • median filtering : given an n-element vector, compute the sliding window median with window size k, • piecewise sorting : given an n-element vector, divide it in n/k blocks of length k and sort each block. By prior work, median filtering is known to be at least as hard as piecewise sorting: with a sing...

متن کامل

ذخیره در منابع من


  با ذخیره ی این منبع در منابع من، دسترسی به آن را برای استفاده های بعدی آسان تر کنید

عنوان ژورنال:

دوره   شماره 

صفحات  -

تاریخ انتشار 2000